From: Marco Trevisan (TreviƱo) Date: Fri, 12 Apr 2019 21:04:16 +0000 (-0500) Subject: popupMenu: Implement Switch as actor X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~845^2^2~203 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=6ecb0a4546f643076f7bf51deb686be73a88aa88;p=gnome-shell.git popupMenu: Implement Switch as actor Switch is used only by menu items, and implement it extending St.Bin https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/499 --- diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js index 83a1d1ced..90319accc 100644 --- a/js/ui/popupMenu.js +++ b/js/ui/popupMenu.js @@ -291,26 +291,27 @@ class PopupSeparatorMenuItem extends PopupBaseMenuItem { } }); -var Switch = class { - constructor(state) { - this.actor = new St.Bin({ style_class: 'toggle-switch', - accessible_role: Atk.Role.CHECK_BOX, - can_focus: true }); +var Switch = GObject.registerClass( +class Switch extends St.Bin { + _init(state) { + super._init({ style_class: 'toggle-switch', + accessible_role: Atk.Role.CHECK_BOX, + can_focus: true }); this.setToggleState(state); } setToggleState(state) { if (state) - this.actor.add_style_pseudo_class('checked'); + this.add_style_pseudo_class('checked'); else - this.actor.remove_style_pseudo_class('checked'); + this.remove_style_pseudo_class('checked'); this.state = state; } toggle() { this.setToggleState(!this.state); } -}; +}); var PopupSwitchMenuItem = GObject.registerClass({ Signals: { 'toggled': { param_types: [GObject.TYPE_BOOLEAN] }, }, @@ -334,7 +335,7 @@ class PopupSwitchMenuItem extends PopupBaseMenuItem { this._statusLabel = new St.Label({ text: '', style_class: 'popup-status-menu-item' }); - this._statusBin.child = this._switch.actor; + this._statusBin.child = this._switch; } setStatus(text) { @@ -344,7 +345,7 @@ class PopupSwitchMenuItem extends PopupBaseMenuItem { this.reactive = false; this.accessible_role = Atk.Role.MENU_ITEM; } else { - this._statusBin.child = this._switch.actor; + this._statusBin.child = this._switch; this.reactive = true; this.accessible_role = Atk.Role.CHECK_MENU_ITEM; } @@ -352,9 +353,8 @@ class PopupSwitchMenuItem extends PopupBaseMenuItem { } activate(event) { - if (this._switch.actor.mapped) { + if (this._switch.mapped) this.toggle(); - } // we allow pressing space to toggle the switch // without closing the menu